package com.hp.ppm.ext.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hp.ppm.ext.kuka.RequestTypeQuery;

@WebServlet(urlPatterns = "/rts")
public class RequestTypeService extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private RequestTypeQuery requestTypeQuery;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username=req.getParameter("mname");
		 resp.setCharacterEncoding("UTF-8");  
		 resp.setContentType("application/json; charset=utf-8"); 
		if(username==null||username.length()<2){
			resp.getOutputStream().print("user name is error");
		}else{
			resp.getOutputStream().write(requestTypeQuery.getRequestTypeJson(username).getBytes("UTF-8"));
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		 doGet(req, resp);
	}

	@Override
	public void destroy() {
		requestTypeQuery=null;
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		try {
			requestTypeQuery=new RequestTypeQuery();
		}catch (Exception e){

		}
	}
	
	
	
	

}
